<template>
  <div>
    <common-head title="编辑联系人"/>
    <div class="wrap">
      <van-address-edit
        :area-list="areaList"
        show-postal
        :address-info="contact"
        show-set-default
        show-delete
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        @delete="ondelete"
      />
    </div>
  </div>
</template>

<script>
import CommonHead from '../../components/CommonHead.vue'
import { areaList } from '@vant/area-data'
import { Toast } from 'vant'
export default {
  data () {
    return {
      areaList,
      contact: {} // 当前编辑的这个联系人
    }
  },
  created () {
    this.fetchContact()
  },
  methods: {
    ondelete () {
      alert(1)
    },
    fetchContact () {
      this.contact = this.$store.state.contact.contacts[parseInt(this.$route.query.index)]
    },
    onSave (contact) {
      console.log(contact)
      this.$store.commit('contact/update_contact', {
        index: parseInt(this.$route.query.index),
        contact
      })
      Toast('修改成功')
      this.$router.replace('/contactLists')
    }
  },
  components: { CommonHead }
}
</script>

<style lang="scss" scoped>
.wrap{
  padding-top: 46px;
}
</style>
